@echo off
chcp 65001 >nul

echo ==========================================
echo 宝塔面板JAR包部署准备脚本
echo ==========================================

echo 创建部署目录...
if not exist bt-jar-deploy mkdir bt-jar-deploy
if not exist bt-jar-deploy\config mkdir bt-jar-deploy\config
if not exist bt-jar-deploy\db mkdir bt-jar-deploy\db
if not exist bt-jar-deploy\logs mkdir bt-jar-deploy\logs

echo 复制JAR包...
copy target\nfc-lock-system-1.0.0.jar bt-jar-deploy\

echo 复制配置文件...
copy src\main\resources\application-prod.yml bt-jar-deploy\config\

echo 复制数据库文件...
copy db\init-database.sql bt-jar-deploy\db\

echo 复制部署说明...
copy "宝塔面板JAR部署说明.md" bt-jar-deploy\

echo 创建启动脚本...
echo #!/bin/bash > bt-jar-deploy\start.sh
echo cd /www/wwwroot/nfc-lock-system >> bt-jar-deploy\start.sh
echo nohup java -jar -Xms512m -Xmx1024m -Dspring.profiles.active=prod nfc-lock-system-1.0.0.jar ^> logs/startup.log 2^>^&1 ^& >> bt-jar-deploy\start.sh

echo 创建停止脚本...
echo #!/bin/bash > bt-jar-deploy\stop.sh
echo PID=$(ps aux ^| grep nfc-lock-system-1.0.0.jar ^| grep -v grep ^| awk '{print $2}') >> bt-jar-deploy\stop.sh
echo if [ ! -z "$PID" ]; then >> bt-jar-deploy\stop.sh
echo   kill -9 $PID >> bt-jar-deploy\stop.sh
echo   echo "应用已停止" >> bt-jar-deploy\stop.sh
echo else >> bt-jar-deploy\stop.sh
echo   echo "应用未运行" >> bt-jar-deploy\stop.sh
echo fi >> bt-jar-deploy\stop.sh

echo 创建部署说明文件...
echo # 宝塔面板JAR包部署文件 > bt-jar-deploy\README.txt
echo. >> bt-jar-deploy\README.txt
echo 1. 将整个bt-jar-deploy目录上传到宝塔面板服务器 >> bt-jar-deploy\README.txt
echo 2. 建议上传到：/www/wwwroot/nfc-lock-system/ >> bt-jar-deploy\README.txt
echo 3. 参考"宝塔面板JAR部署说明.md"进行配置 >> bt-jar-deploy\README.txt
echo 4. 修改config/application-prod.yml中的数据库密码 >> bt-jar-deploy\README.txt
echo 5. 导入db/init-database.sql到MySQL数据库 >> bt-jar-deploy\README.txt
echo 6. 运行start.sh启动应用 >> bt-jar-deploy\README.txt
echo. >> bt-jar-deploy\README.txt
echo JAR包信息： >> bt-jar-deploy\README.txt
echo - 文件名：nfc-lock-system-1.0.0.jar >> bt-jar-deploy\README.txt
echo - 大小：约55MB >> bt-jar-deploy\README.txt
echo - Java版本要求：Java 17+ >> bt-jar-deploy\README.txt
echo - 运行端口：8080 >> bt-jar-deploy\README.txt

echo 设置脚本权限说明...
echo echo "chmod +x start.sh stop.sh" > bt-jar-deploy\set-permissions.sh

echo ==========================================
echo 部署文件准备完成！
echo ==========================================
echo.
echo 部署文件位置：bt-jar-deploy\
echo.
echo 文件清单：
dir bt-jar-deploy
echo.
echo 上传步骤：
echo 1. 将bt-jar-deploy目录压缩为zip文件
echo 2. 通过宝塔面板文件管理器上传到服务器
echo 3. 解压到/www/wwwroot/nfc-lock-system/
echo 4. 按照"宝塔面板JAR部署说明.md"进行配置
echo.
echo 快速启动命令：
echo cd /www/wwwroot/nfc-lock-system
echo chmod +x start.sh stop.sh
echo ./start.sh

pause